<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>利用set类型对两个去重后的数组求交集、并集、差集</title>
</head>
<body>
    <script>
        let arr1 = [1,2,3,4,5,6,7,8];
        let arr2 = [3,5,7,9,11,13];
        let newArr1 = [...new Set(arr1)];
        let newArr2 = [...new Set(arr2)];
        console.log(newArr1);
        console.log(newArr2);
        // 1. 交集
        let mixedArr = newArr1.filter(item=>{
            return newArr2.includes(item)
        })
        console.log(mixedArr,1111);      // [23]
        // 2. 并集
        let union = [...new Set([...newArr1,...newArr2])];
        console.log(union,222);     //  [23, 54, 7, 8, 21, 67, 43, 14, 64, 24, 12, 32, 87]
        // 3. 差集
        let diffArr = union.filter(item=>{
            return !mixedArr.includes(item)
        })
        console.log(diffArr,333);       // [54, 7, 8, 21, 67, 43, 14, 64, 24, 12, 32, 87]
    </script>
</body>
</html>